$(function() {
	$("input[name='start_date']").val("2017-01-01");
	var mydate = new Date();
	$("input[name='end_date']").val(getNowTime(false));
	show_home_data();
	/*
	 * 首页选择后输出数据
	 */
	$(".home_confirm").on("click", function() {
		var now_staff_id = $("select[name='staff_id']").val();
		var now_start_date = $("input[name='start_date']").val();
		var now_end_date = $("input[name='end_date']").val();
		show_home_data(now_staff_id, now_start_date, now_end_date);
	})
	/*
	 * 首页显示数据
	 */
	function show_home_data(now_staff_id, now_start_date, now_end_date) {
		var mydate = new Date();
		var myChart_visit_state = echarts.init(document.querySelector('#visit_state'));
		var myChart_intention_id = echarts.init(document.querySelector('#intention_id'));
		var myChart_channel_id = echarts.init(document.querySelector('#channel_id'));
		var myChart_all_data = echarts.init(document.querySelector('#all_data'));
		var now_staff_id = now_staff_id ? now_staff_id : 999;
		var now_start_date = now_start_date ? now_start_date : "2017-01-01";
		var now_end_date = now_end_date ? now_end_date : getNowTime(false);
		var data = {
			"now_staff_id": now_staff_id,
			"now_start_date": now_start_date,
			"now_end_date": now_end_date
		}
		var request_url = package_url("home/index/show_home_data");
		crm_ajax(data, request_url, function(res) {
			if(res.status == 1) {
				var option_visit_state = pie("咨询者上门率", "上门情况", res.data.res_visit_state);
				var option_intention_id = pie("咨询者意向率", "意向情况", res.data.res_intention_id);
				var option_channel_id = pie("咨询者渠道占比率", "渠道占比情况", res.data.res_channel_id);
				var option_all_data = line("每日咨询者个数", res.data.date_arr, res.data.res_all_data);
				myChart_visit_state.setOption(option_visit_state);
				myChart_intention_id.setOption(option_intention_id);
				myChart_channel_id.setOption(option_channel_id);
				myChart_all_data.setOption(option_all_data);
			} else {
				crm.alert(res.msg, "error");
			}
		})
	}
})